package com.exia.android.socialnet.facebook;

import org.json.JSONException;
import org.json.JSONObject;

import android.util.Log;

import com.facebook.android.FacebookError;
import com.facebook.android.Util;

public class FacebookRequestListener extends BaseRequestListener {

	protected FacebookActivity activity;
	
	public FacebookRequestListener(){
		super();
		activity = null;
	}
	
	public FacebookRequestListener(FacebookActivity activity_p){
		super();
		activity = activity_p;
	}
	
	/**
	 * 
	 * @return
	 */
	public FacebookActivity getFacebookActivity(){
		return activity;
	}
	
	/**
	 * 
	 * @param activity_p
	 */
	public void setFacebookActivity(FacebookActivity activity_p){
		activity = activity_p;
	}
	
	@Override
	public void onComplete(final String response) {
        if((activity != null)){
        	/*
        	try {
                // process the response here: executed in background thread
                Log.d("Facebook-Example", "Response: " + response.toString());
                JSONObject json = Util.parseJson(response);
                final String name = json.getString("name");

                // then post the processed result back to the UI thread
                // if we do not do this, an runtime exception will be generated
                // e.g. "CalledFromWrongThreadException: Only the original
                // thread that created a view hierarchy can touch its views."
                activity.runOnUiThread(new Runnable() {
                    public void run() {
                        activity.mText.setText("Hello there, " + name + "!");
                    }
                });
            } catch (JSONException e) {
                Log.w("Facebook-Example", "JSON Error in response");
            } catch (FacebookError e) {
                Log.w("Facebook-Example", "Facebook Error: " + e.getMessage());
            }
            */
        }
    }

}
